
/****** Object:  LinkedServer [ExcelServer] as Connecting an Excel File   ******/
EXEC sp_addLinkedServer 
     @server = 'ExcelServer', 
     @srvproduct = 'ACE 12.0', 
     @provider = 'Microsoft.ACE.OLEDB.12.0', 
     @datasrc= 'E:\DatabaseDoc.xlsx', 
     @provstr = 'Excel 12.0; HDR=No'
  
EXEC sp_addlinkedserver @server = 'ExcelServer',
   @srvproduct = 'Jet 4.0',
   @provider = 'Microsoft.Jet.OLEDB.4.0',
   @datasrc= 'E:\DatabaseDoc.xls',
   @provstr = 'Excel 8.0; HDR=Yes'
   
 EXEC MASTER.dbo.sp_addlinkedsrvlogin @rmtsrvname = N'ExcelServer', @locallogin = 'sa', @useself = 
      N'False', @rmtuser = N'admin', @rmtpassword = N''  
     
/****** Object:  LinkedServer [MainServer] as Connecting another Sql Server   ******/
EXEC sp_addlinkedserver 
     @server = N'MainServer', @srvproduct = N'', @provider = N'SQLNCLI', @datasrc = 
     N'<Any server>';
 /* For security reasons the linked server remote logins password is changed with ######## */
EXEC MASTER.dbo.sp_addlinkedsrvlogin @rmtsrvname = N'MainServer', @useself = N'False', @locallogin
     = 'sa', @rmtuser = '<login Id for that server>', @rmtpassword = '<login Password for that server>'

GO

